import 'dart:math';

import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter/rendering.dart';
import 'package:english_words/english_words.dart';

class WidgetStatusManage extends StatefulWidget {
  const WidgetStatusManage({required Key key});

  @override
  _ScrollbarWidgetState createState() => new _ScrollbarWidgetState();
}

class _ScrollbarWidgetState extends State<WidgetStatusManage> {



  @override
  void initState() {
    super.initState();
    //初始化状态
    print("initState");
  }




  @override
  Widget build(BuildContext context) {
    print("build");

    var _positionFlag = false;
    void _invertColorFlag() {

    }
    void _invertPositionFlag() {
      _positionFlag = !_positionFlag;
      setState(() {
      });
    }

    var contents = <Widget>[
      new RaisedButton(
        child: const Text('Change Color'),
        onPressed: () { _invertColorFlag(); },
      ),
      const SizedBox(height: 10.0),
      new RaisedButton(
        child: const Text('Change Position'),
        onPressed: () { _invertPositionFlag(); },
      ),
    ];


    var text = 10;
    void _chageText() {
      setState(() {
        text =text + new Random().nextInt(100);
      });
    }

    final statefulWidget = new TextButton(
        child: Text("${text}"),
        style: ButtonStyle(),
        onPressed: _chageText
      //导航到新路由
    );



    if (_positionFlag) {
      contents.add(statefulWidget);
    } else {
      contents.insert(0, statefulWidget);
    }



    return Scaffold(
      appBar: new AppBar(
        title: const Text('Stateful Demo'),
      ),
      body: new Center(
        child: new Column(
          mainAxisSize: MainAxisSize.min,
          children: contents,
        ),
      ),

    );
  }

  @override
  void didUpdateWidget(covariant WidgetStatusManage oldWidget) {
    // TODO: implement didUpdateWidget
    super.didUpdateWidget(oldWidget);
  }

  @override
  void deactivate() {
    super.deactivate();
    print("deactive");
  }

  @override
  void dispose() {
    super.dispose();
    print("dispose");
  }

  @override
  void reassemble() {
    super.reassemble();
    print("reassemble");
  }

  @override
  void didChangeDependencies() {
    super.didChangeDependencies();
    print("didChangeDependencies");
  }
}



